﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.ServiceModel.DomainServices.Client;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Linq;

using NetBay.Core.BusinessEntities;

using Rio.Applications.Web.Services;
using Rio.Framework.Localisation;
using Rio.Framework.Pages.AppCode.Context;
using Rio.Framework.Pages.AppCode.Enums;
using Rio.Framework.Pages.AppCode.Events;
using Rio.Framework.Pages.Context;
using Rio.Framework.Pages.Events;
using Rio.Framework.Pages.Manager;
using Rio.Framework.Pages.UserControls;
using Rio.Framework.Pages.ChildWindows;


namespace Rio.Framework.Pages.Controls
{

    public partial class FlowIndexPanel
    {
        #region Fields

        private int L_iActivePanel = 0;
        private Folder m_oFolderSelectedOnSearch = null;
        private WorkflowManager _workflowManager;

        #endregion Fields

        #region Constructors

        public FlowIndexPanel(List<Document> p_lfilesToIndex, WorkflowManager workflowManager = null)
        {
            InitializeComponent();
            InitLabel();

            _workflowManager = workflowManager;

            if (p_lfilesToIndex != null 
                && p_lfilesToIndex.Count > 0)
            {
                m_oListSelectedFilename = p_lfilesToIndex;
                textboxCreditPhoto.Text = p_lfilesToIndex[0].PhotoCredit;
            }

            informationsTabControl.IsEnabled = false;

            //UCOrganizationType init
            UCOrganizationType.OrganizationSelected += cbEntity_SelectionChanged;
            UCOrganizationType.FolderSelected += cbFolderType_SelectionChanged;
            UCOrganizationType.InitControl(AppDisplayMode.Import);

            LayoutRoot.KeyDown += LayoutRoot_KeyDown;
        }

        #endregion Constructors

        #region Events

        public event EventHandler CancelClickEvent;
        public event IndexedFilesEventHandler ValidateClickEvent;

        /// <summary>
        /// method for raise the event 'ValidateClickEvent'
        /// </summary>
        private void OnValidateClickEvent(List<Document> indexDocuments)
        {
            if (ValidateClickEvent != null)
                ValidateClickEvent(this, new IndexedFilesEventArgs() { IndexDocuments = indexDocuments, Organization = m_oOrganization, FolderType = m_oFolderType});
        }

        /// <summary>
        ///  method for raise the event 'CancelClickEvent'
        /// </summary>
        private void OnCancelClickEvent()
        {
            if (CancelClickEvent != null)
                CancelClickEvent(this, EventArgs.Empty);
        }

        #endregion Events

        #region Properties

        /// <summary>
        /// Gets a value indicating whether this instance is workflow indexing.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is workflow indexing; otherwise, <c>false</c>.
        /// </value>
        private bool IsWorkflowIndexing
        {
            get
            {
                return _workflowManager != null;
            }
        }

        /// <summary>
        ///  List Thumbnails selected
        /// </summary>
        public new List<Document> m_oListSelectedFilename
        {
            get; set;
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Translation
        /// </summary>
        public override void InitLabel()
        {
            base.InitLabel();

            labelFolder.Text = Resx.GetLabel(ResxIndexPanel.FOLDER);
            labelIndexTabHeader.Text = Resx.GetLabel(ResxIndexPanel.INDEX_TAB_HEADER);
            labelInfoDoc.Text = Resx.GetLabel(ResxIndexPanel.INFO_DOCUMENT);
            labelNote.Text = Resx.GetLabel(ResxIndexPanel.NOTE);
            labelCreditPhoto.Text = Resx.GetLabel(ResxIndexPanel.PHOTO_CREDIT);
            labelAuthor.Text = Resx.GetLabel(ResxIndexPanel.AUTHOR);
            labelPublicationDate.Text = Resx.GetLabel(ResxIndexPanel.PUBLICATION_DATE);
            labelVideoTime.Text = Resx.GetLabel(ResxIndexPanel.VIDEO_TIME);
            checkBoxFullText.Content = Resx.GetLabel(ResxIndexPanel.FULLTEXT_ENABLE);
            checkBoxKeepCriteria.Content = Resx.GetLabel(ResxIndexPanel.KEEP_FLOW_CRITERIA_CHECKBOX);
            TextBlockClear.Text = Resx.GetLabel(ResxIndexPanel.CLEAR_CRITERIA);
            TextBlockToIndex.Text = Resx.GetLabel(ResxIndexPanel.TOINDEX);
            TextBlockToSearch.Text = Resx.GetLabel(ResxSearchPanel.SEARCH);
            TextBlockCancel.Text = Resx.GetLabel(ResxAlert.CLOSE);
        }

        /// <summary>
        /// Clear criteria
        /// </summary>
        protected void ClearCriterias()
        {
            StackIndex.ClearCriterias();
            ClearDocumentInformation();
            ClearSelectedItem();
            checkBoxFullText.IsChecked = true;
        }

        /// <summary>
        /// Clear the selected item       
        /// </summary>
        protected void ClearSelectedItem()
        {
            TreeViewControlItems.ClearSelection();
        }

        /// <summary>
        /// Clear documents informations
        /// </summary>
        protected void ClearDocumentInformation()
        {
            textboxAuthor.Text = String.Empty;
            textboxCreditPhoto.Text = String.Empty;
            textboxNote.Text = String.Empty;
            textboxVideoTime.Text = String.Empty;
            DatePickerPublicationDate.SelectedDate = null;
        }

        /// <summary>
        /// Launch cancelation
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void buttonCancel_Click(object sender, RoutedEventArgs e)
        {
            OnCancelClickEvent();
        }

        /// <summary>
        /// Clear button action
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void buttonClear_Click(object sender, RoutedEventArgs e)
        {
            ClearCriterias();
        }

        /// <summary>
        /// Launch indexing
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void buttonToIndex_Click(object sender, RoutedEventArgs e)
        {
            IndexFiles();
        }

        /// <summary>
        /// Launch Search
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void buttonToSearch_Click(object sender, RoutedEventArgs e)
        {
            //Get the list of values for each index
            Dictionary<long, string> listIndexValue = StackIndex.GetIndexIdValuesToSearch();

            SearchFinished += IndexPanel_SearchFinished;

            try
            {
                Search(m_oOrganization, m_oFolderType, listIndexValue);
            }
            catch
            {
                SearchFinished -= IndexPanel_SearchFinished;

                MessageBoxChildWindow L_oCriteriaMessage = new MessageBoxChildWindow(String.Empty, m_sLblNoCriteria, MessageBoxButtons.Ok, MessageBoxIcon.Warning);
                L_oCriteriaMessage.ShowDialog();
            }
        }

        /// <summary>
        /// The selected organization change
        /// We have to reload the corresponding folder type
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rio.Framework.Pages.Controls.OrganizationSelectedEventArgs" /> instance containing the event data.</param>
        private void cbEntity_SelectionChanged(object sender, OrganizationSelectedEventArgs e)
        {
            m_oOrganization = e.Organization;
            informationsTabControl.IsEnabled = false;
            ClearCriterias();
        }

        /// <summary>
        /// Handles the SelectionChanged event of the cbFolderType control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rio.Framework.Pages.Controls.FolderSelectedEventArgs" /> instance containing the event data.</param>
        private void cbFolderType_SelectionChanged(object sender, FolderSelectedEventArgs e)
        {
            m_oFolderType = e.FolderType;

            ClearCriterias();

            InitPanelControls();

            //Init index values and keepindex checkbox
            InitializeWorkflow();
        }

        /// <summary>
        /// Inits the panel controls.
        /// </summary>
        private void InitPanelControls()
        {
            // clear index control (dynamique folder search index control)
            StackIndex.Clear();

            if (m_oFolderType != null)
            {
                m_oListIndex = new List<Index>(m_oFolderType.LstIndex);

                InitIndexControl();

                InitItems(m_oFolderType);

                informationsTabControl.IsEnabled = true;
            }
        }

        /// <summary>
        /// Handles the GotFocus event of the Control control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void Control_GotFocus(object sender, RoutedEventArgs e)
        {
            if (sender is FrameworkElement)
            {
                indexScrollViewer.ScrollIntoView(sender as FrameworkElement);
            }
        }

        /// <summary>
        /// Index the current existing file.
        /// </summary>
        private new void IndexFiles()
        {
            if (m_oListSelectedFilename != null)
            {
                DesactivatePanel();
                L_iActivePanel = m_oListSelectedFilename.Count;
            }
            else
            {
                L_iActivePanel = 0;
            }

            string L_oSelectedNodeCode = string.Empty;
            BusinessEntitiesDomainContext l_oBEDomainContext = new BusinessEntitiesDomainContext();

            if ((m_oOrganization != null) && (m_oFolderType != null))
            {
                //List of criteria and values
                Dictionary<long, string> l_oCriteriaFilter;
                Dictionary<long, string> l_oUnicityIndex;

                //If all mandatory criteria are inputed, we can follow the indexation
                if (StackIndex.IsMandatoryIndexSatisfied())
                {

                    l_oCriteriaFilter = StackIndex.GetIndexIdValues();
                    l_oUnicityIndex = StackIndex.GetUniqueIndexValues();

                    //Selected item code
                    if (TreeViewControlItems.CurrentSelectedItem != null)
                    {
                        L_oSelectedNodeCode = TreeViewControlItems.CurrentSelectedItem.Code;
                    }

                    //For each File selected, we index the file
                    if ((m_oListSelectedFilename != null) && (m_oListSelectedFilename.Count > 0))
                    {
                        
                        textboxCreditPhoto.Text = m_oListSelectedFilename[0].PhotoCredit;

                        l_oBEDomainContext.IsFolderExist(m_oOrganization.Identifier, m_oFolderType.Identifier, l_oCriteriaFilter, false, delegate(InvokeOperation<ReturnLong> retr)
                        {
                            if (retr != null && retr.Value != null && retr.Value.Value != 0)
                            {
                                MessageBoxChildWindow L_oMessage = new MessageBoxChildWindow("", m_szMsgFolderExists, MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                                L_oMessage.ShowDialog();
                                L_oMessage.Closed += (s, ev) =>
                                {
                                    if (L_oMessage.Result == MessageBoxResult.Yes)
                                    {
                                        SplashScreenManager.Wait(this);
                                        Dictionary<string, string> l_oSelectedFileInfo = new Dictionary<string, string>();
                                        List<string> l_oSelectedFileNames = new List<string>();
                                        foreach (Document selectedFileName in m_oListSelectedFilename)
                                        {
                                            l_oSelectedFileInfo.Add(selectedFileName.OriginalNameFile, selectedFileName.RelativePath + "\\" + selectedFileName.ImageName);
                                            l_oSelectedFileNames.Add(selectedFileName.OriginalNameFile);
                                        }

                                        var query = l_oBEDomainContext.AddIndexationToExistingFileQuery(m_oOrganization.Identifier, m_oFolderType.Identifier,
                                                                        l_oCriteriaFilter,
                                                                        l_oSelectedFileNames,
                                                                        l_oSelectedFileInfo,
                                                                        L_oSelectedNodeCode,
                                                                        textboxNote.Text.Trim(), textboxAuthor.Text.Trim(),
                                                                        textboxVideoTime.Text.Trim(), ChronoName, ChronoId, true);

                                        l_oBEDomainContext.Load(query, OnAddIndexationToExistingFileQueryCallback, null);
                                    }
                                    else
                                    {
                                        SplashScreenManager.Stop(this);
                                        ActivatePanel();
                                    }
                                };
                            }
                            else
                            {

                                //** if no folder found check unicity of the index
                                l_oBEDomainContext.CheckUnicityOfIndexValue(m_oFolderType.Identifier, l_oUnicityIndex, 0, delegate(InvokeOperation<IEnumerable<long>> CheckUnicityReturn)
                                {
                                    if (CheckUnicityReturn.Value != null && CheckUnicityReturn.Value.Count() == 0)
                                    {

                                        SplashScreenManager.Wait(this);

                                        Dictionary<string, string> l_oSelectedFileInfo = new Dictionary<string, string>();
                                        List<string> l_oSelectedFileNames = new List<string>();
                                        foreach (Document selectedFileName in m_oListSelectedFilename)
                                        {
                                            l_oSelectedFileInfo.Add(selectedFileName.OriginalNameFile, selectedFileName.RelativePath + "\\" + selectedFileName.ImageName);
                                            l_oSelectedFileNames.Add(selectedFileName.OriginalNameFile);
                                        }

                                        var query = l_oBEDomainContext.AddIndexationToExistingFileQuery(m_oOrganization.Identifier, m_oFolderType.Identifier,
                                                                        l_oCriteriaFilter,
                                                                        l_oSelectedFileNames,
                                                                        l_oSelectedFileInfo,
                                                                        L_oSelectedNodeCode,
                                                                        textboxNote.Text.Trim(), textboxAuthor.Text.Trim(),
                                                                        textboxVideoTime.Text.Trim(), ChronoName, ChronoId, true);

                                        l_oBEDomainContext.Load(query, OnAddIndexationToExistingFileQueryCallback, null);

                                    }
                                    else
                                    {

                                        //highlight control
                                        List<long> l_oListIndex = new List<long>(CheckUnicityReturn.Value);
                                        StackIndex.ChangeBorderColor(l_oListIndex, Colors.Red);

                                        SplashScreenManager.Stop(this);
                                        ActivatePanel();
                                        MessageBoxChildWindow L_oMessage = new MessageBoxChildWindow("", m_szMsgNoUnicity, MessageBoxButtons.Ok, MessageBoxIcon.Information);
                                        L_oMessage.ShowDialog();
                                    }
                                }, null); //CheckUnicityOfIndexValue

                            }

                        }, null);
                    }
                    else
                    {
                        ActivatePanel();
                        MessageBoxChildWindow L_oMessage = new MessageBoxChildWindow("", m_szLabelNoImageSelected, MessageBoxButtons.Ok, MessageBoxIcon.Information);
                        L_oMessage.ShowDialog();

                    }

                }
                else
                {
                    ActivatePanel();
                    MessageBoxChildWindow L_oMessage = new MessageBoxChildWindow(String.Empty, m_szLabelMandatoryField, MessageBoxButtons.Ok, MessageBoxIcon.Error);
                    L_oMessage.ShowDialog();
                }
            }
            else
            {
                ActivatePanel();
            }
        }

        /// <summary>
        /// Indexes the panel_ search finished.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void IndexPanel_SearchFinished(object sender, ObservableCollection<Folder> e)
        {
            SearchFinished -= IndexPanel_SearchFinished;

            if (e.Count == 0)
            {
                /*
                 * No Folder
                 */

                MessageBoxChildWindow msg = new MessageBoxChildWindow(String.Empty, Resx.GetLabel(ResxCommon.SEARCH_RESULT_IS_EMPTY), MessageBoxButtons.Ok, MessageBoxIcon.Information);
                msg.ShowDialog();
            }
            else if (e.Count == 1)
            {
                /*
                 * Just 1 so we fill index values
                 */

                LoadSelectedFolderInformation(null, e.FirstOrDefault(), m_oFolderType, m_oOrganization);
            }
            else
            {
                /*
                 * Several folders, so we display the popup
                 */

                FolderSearchChildWindow window = new FolderSearchChildWindow(GlobalWebContext.CurrentUser, m_oOrganization, m_oFolderType, StackIndex.GetIndexValuesToSearch(), e)
                {
                    Width = ((UserControl)Application.Current.RootVisual).ActualWidth - 30,
                    Height = ((UserControl)Application.Current.RootVisual).ActualHeight - 30,
                };

                window.LoadSelectedFolderInformationFromList += LoadSelectedFolderInformation;

                window.ShowDialog();
            }
        }

        /// <summary>
        /// Add index criteria control with help assistance values (with filter and without filter)
        /// </summary>
        private void InitIndexControl()
        {

            if ((m_oOrganization != null) && (m_oFolderType != null))
            {
                if ((m_oFolderSelectedOnSearch != null) && (m_oFolderSelectedOnSearch.ListValues != null))
                {
                    InitExistingFolder();
                }
                else
                {
                    InitNonExistingFolder();
                }
            }
        }

        /// <summary>
        /// Initialize items'treeview from a XDocument
        /// </summary>
        /// <param name="P_oFolderType">Type of the p_o folder.</param>
        private void InitItems(FolderType P_oFolderType)
        {
            TreeViewControlItems.InitItems(P_oFolderType);
            TreeViewControlItems.SelectDefaultItem();
            if (TreeViewControlItems.ItemsList.Count == 1)
            {
                itemsTabItem.IsEnabled = false;
            }
            else
            {
                itemsTabItem.IsEnabled = true;
            }
        }

        /// <summary>
        /// run indexing with enter key
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.KeyEventArgs" /> instance containing the event data.</param>
        private void LayoutRoot_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter && buttonToIndex.IsEnabled)
            {
                buttonToIndex_Click(this, null);
            }
        }

        /// <summary>
        /// Load the folder informations
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="P_oFolder">The p_o folder.</param>
        /// <param name="P_oFolderType">Type of the p_o folder.</param>
        /// <param name="P_oOrganization">The p_o organization.</param>
        private void LoadSelectedFolderInformation(object sender, Folder P_oFolder, FolderType P_oFolderType, Organization P_oOrganization)
        {
            if (sender != null)
            {
                FolderSearchChildWindow windowSource = sender as FolderSearchChildWindow;
                windowSource.LoadSelectedFolderInformationFromList -= LoadSelectedFolderInformation;
            }

            CurrentFolder = P_oFolder;
            m_oFolderSelectedOnSearch = P_oFolder;

            if (UCOrganizationType.SelectedOrganization != P_oOrganization)
                UCOrganizationType.SelectedOrganization = P_oOrganization;

            if (UCOrganizationType.SelectedFolderType != P_oFolderType)
                UCOrganizationType.SelectedFolderType = P_oFolderType;

            InitPanelControls();
        }

        /// <summary>
        /// Handles the GotFocus event of the L_oUiElementIndexControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void L_oUiElementIndexControl_GotFocus(object sender, RoutedEventArgs e)
        {
            if (sender is FrameworkElement)
            {
                indexScrollViewer.ScrollIntoView(sender as FrameworkElement);
            }
        }

        /// <summary>
        /// Called when [add indexation to existing file query callback].
        /// </summary>
        /// <param name="result">The result.</param>
        private void OnAddIndexationToExistingFileQueryCallback(LoadOperation<Document> result)
        {
            try
            {
                List<Document> l_oReturnObjects = new List<Document>(result.Entities);

                //Fix chrono number is needed
                if (!string.IsNullOrEmpty(ChronoName))
                {
                    GetDataContext.FixChrono(ChronoName, OnFixChronoCallback, null);
                }
            
                ActivatePanel();

                OnValidateClickEvent(l_oReturnObjects);

                SplashScreenManager.Stop(this);
            }
            catch (Exception ex)
            {
                //Active the Panel
                L_iActivePanel--;
                if (L_iActivePanel == 0)
                {
                    ActivatePanel();
                }

                // Ajout bug uri
                if (m_iNumberOfDocAdd == m_iNumberOfAddedDoc)
                {
                    MessageBoxChildWindow L_oMessage = new MessageBoxChildWindow(String.Empty, " -> OnSearchDocumentsQueryCallback failure Error : " + Environment.NewLine + ex.Message, MessageBoxButtons.Ok, MessageBoxIcon.Error);
                    L_oMessage.ShowDialog();
                }

                OnCancelClickEvent();
            }
        }

        /// <summary>
        /// Inits the folder.
        /// </summary>
        private void InitNonExistingFolder()
        {
            //Add each controls on the panel
            StackIndex.InitializeControl(m_oOrganization, m_oFolderType);
        }

        /// <summary>
        /// Inits the existing folder.
        /// </summary>
        private void InitExistingFolder()
        {
            StackIndex.InitializeControl(m_oOrganization, m_oFolderType, new List<string>(m_oFolderSelectedOnSearch.ListValues));

            //Clear current folder after initialization of index to avoid a new databinding of index values at the folder type changing
            m_oFolderSelectedOnSearch = null;

            //Activate indexation
            buttonToIndex.IsEnabled = true;
            m_oFolderSelectedOnSearch = null;
        }

        /// <summary>
        /// Initializes the workflow.
        /// </summary>
        private void InitializeWorkflow()
        {
            if(IsWorkflowIndexing)
            {
                //The selected foldertype and worflow foldertype are the same
                if (_workflowManager.FolderType != null && m_oFolderType != null && m_oFolderType.Identifier == _workflowManager.FolderType.Identifier)
                {
                    //set index values
                    var folder = _workflowManager.Folder;
                    if (folder != null && UserWebContext.GetCurrent().KeepCriteriaOnFlowIndexing.Value)
                    {
                        StackIndex.ClearCriterias();
                        StackIndex.InitializeControl(m_oOrganization, m_oFolderType, new List<string>(folder.ListValues));
                    }

                    checkBoxKeepCriteria.Visibility = Visibility.Visible;
                    checkBoxKeepCriteria.IsChecked = UserWebContext.GetCurrent().KeepCriteriaOnFlowIndexing;
                }
                else
                {
                    checkBoxKeepCriteria.Visibility = Visibility.Collapsed;
                }
            }
        }

        private void checkBoxKeepCriteria_Checked(object sender, RoutedEventArgs e)
        {
            UserWebContext.GetCurrent().KeepCriteriaOnFlowIndexing = true;
        }

        private void checkBoxKeepCriteria_Unchecked(object sender, RoutedEventArgs e)
        {
            UserWebContext.GetCurrent().KeepCriteriaOnFlowIndexing = false;
        }

        #endregion Methods

        #region Specific Flow

        /// <summary>
        /// Ventil the document after the chrono has been fixed
        /// </summary>
        /// <param name="p_oResult"></param>
        private void OnFixChronoCallback(InvokeOperation<ReturnBoolean> p_oResult)
        {
            ReturnBoolean l_oReturn = p_oResult.Value;
            if (l_oReturn.IsValid)
            {
                //Remove chrono and Clear the folder indexes
                StackIndex.RemoveChrono();
                ChronoName = string.Empty;
                ChronoId = 0;
                StackIndex.ClearCriterias();
                ClearDocumentInformation();
                checkBoxFullText.IsChecked = true;
            }
        }

        /// <summary>
        /// Handles the ChronoNumberGenerated event of the StackIndex control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="Rio.Framework.Pages.CriteriaControls.StackIndexControl.ChronoNumberGeneratedEventArgs" /> instance containing the event data.</param>
        private void StackIndexChronoNumberGenerated(object sender, CriteriaControls.StackIndexControl.ChronoNumberGeneratedEventArgs args)
        {
            ChronoName = args.ChronoName;
            ChronoId = args.ChronoId;
        }

        private void TreeViewControlItemsPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (TreeViewControlItems.CurrentSelectedItem != null)
                labelItemsTabHeader.Text =
                    TreeViewControlItems.
                        CurrentSelectedItem.Text;
        }

        #endregion



    }
}